﻿package {
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.types.Texture;
	
	import flash.geom.Point;
	
	public class TexturedHouse extends Piece {
		
		[Embed(source="images/wall.jpg")] private static const bmpWall:Class;
		[Embed(source="images/roof.jpg")] private static const bmpRoof:Class;		
		private static const wallTexture:Texture = new Texture(new bmpWall().bitmapData, "wall");
		private static const roofTexture:Texture = new Texture(new bmpRoof().bitmapData, "roof");
		
		[Embed(source="images/murD.jpg")] private static const imageMur2C:Class;
		private static const murFacePorte:Texture = new Texture(new imageMur2C().bitmapData, "mur2coul");
		
		public function TexturedHouse(x:Number,y:Number,z:Number,p:Number,name:String=null) {
			super(x,y,z,p,name);
			
		}
		
		/**
		 * @inheritDoc
		 */		
		override protected function setMaterials():void {

			setUVs();
			setMaterialToSurface(new TextureMaterial(wallTexture), "walls");
			setMaterialToSurface(new TextureMaterial(murFacePorte,1,true,false,"normal",-1,0,1),"FP");

		}
		
		/**
		 * Mapping UV for house box and roof
		 */
		private function setUVs():void {
				
				//setUVsToFace(new Point(0, 0), new Point(1,0), new Point(1, 1), "bas");
				//setUVsToFace(new Point(0, 0), new Point(1,0), new Point(1, 1), "haut");
				setUVsToFace(new Point(0, 0), new Point(1,0), new Point(1, 1), "wall_2");
				setUVsToFace(new Point(0, 0), new Point(1,0), new Point(1, 1), "wall_4");
				
				setUVsToFace(new Point(0, 0), new Point(10,0), new Point(10, 10), "wall_5");
				setUVsToFace(new Point(0, 0), new Point(10,0), new Point(10, 10), "wall_3");
	
				
		}
		
		
		private function getHypotenuse(a:Number, b:Number):Number {
			return Math.sqrt(a * a + b * b);
		}
	}
}